import { h } from "koishi"

export const name = "message-filter"

export function apply(ctx) {
  ctx.middleware((session, next) => {
    const text = h("", session.elements).toString(true).replace(/(data:[0-9a-z-]+\/[0-9a-z-]+;base64,|base64:\/\/)[0-9A-Za-z/+]+/, "")
    if (text.match(/((?<!\d)|(?<=1\W*9))\W*8\W*9\D*?(6\D*?|0?\W*6\D*?0\W*)4(?!\W*[1-9])/)) {
      session.onebot?._request("set_msg_emoji_like", { message_id: session.messageId, emoji_id: 128560 }).catch(() => {})
      return
    }
    return next()
  }, true)
}
